$(function () {
    $("#jqGrid").jqGrid({
        url:' /xietong-enterprise/enterprise/enterprise/changeRoleList',
        datatype: "json",
        colModel: [			
        	{ label: '用户ID', hidden:true, name: 'userId', index: "userId", width: 45 },
			{ label: '企业ID', name: 'enterpriseId', index: "enterpriseId", width: 45, key: true },
			{ label: '企业名称', name: 'enterpriseName', index: "enterpriseName", width: 75 },
			{ label: '企业行业', name: 'moduleName',index: "moduleName", width: 100 },
			{ label: '企业角色', name: 'roleName', index: "roleName", width: 80}
        ],
		viewrecords: true,
        height: Commons.getGridHeight("jqGrid"),
        rowNum: 20,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

	
var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			enterpriseName: null,
			moduleId:'',
			role:'',
			roleId:'',
			userId:'',
			enterpriseId:''
			
		}
	},
	methods: {
		changeRole: function(){
			var moduleId=vm.q.moduleId;
			var enterpriseId = getSelectedRow();
			var role=vm.q.role;
			var roleId=0;
			if(enterpriseId==undefined){
				alert("请选择一条记录");
				return
			}
			if(moduleId==undefined){
				alert("请选择行业");
				return
			}
			if(role==undefined){
				alert("请选择角色");
				return
			}
			if(role=='sc'){
				if(moduleId==12){
					roleId=12;
				}else if(moduleId==13){
					roleId=13;
				}else if(moduleId==14){
					roleId=14;
				}
			}else if(role=='fw'){
				if(moduleId==12){
					roleId=15;
				}else if(moduleId==13){
					roleId=16;
				}else if(moduleId==14){
					roleId=17;
				}
			}else if(role=='jx'){
				if(moduleId==12){
					roleId=18;
				}else if(moduleId==13){
					roleId=19;
				}else if(moduleId==14){
					roleId=20;
				}
			}
			vm.q.roleId=roleId;
			vm.q.enterpriseId=enterpriseId;
			vm.q.userId=getSelectedValue("userId");
			console.log(vm.q);
			var url = "";
			$.ajax({
				type: "POST",
			    url: "/xietong-enterprise/enterprise/enterprise/changeRole",
                contentType: "application/json",
			    data: JSON.stringify(vm.q),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(){
							vm.reload();
						});
					}else{
						alert(r.msg);
						
					}
				}
			});
			
		},
		query: function(){
			vm.reload();
		},
		reload: function () {
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData:{'name': vm.q.enterpriseName},
                page:page
            }).trigger("reloadGrid");
		},
        
	}
});

$(function() {
	vm.q.moduleId=12;
	vm.q.role='sc';
	
});
